package cn.Arrger1;

import cn.Duo.A;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;

/*用于集合--ArrayList    LinkedList
* ArrayList 与数组相似,顺序排列,访问速度快,插入和删除速度较慢
* LinkedList  采用链表数据结构,访问速度慢,插入和删除速度快
* */
public class Jihe {
    public static void main(String[] args) {
        ArrayList arrayList = new ArrayList();
        arrayList.add("a");
        arrayList.add("b");
        arrayList.add("c");
        System.out.println("arrayList的元素为:"+arrayList);//a,b,c
        arrayList.set(0,"c");
        System.out.println("arrayList的元素为:"+arrayList);//c,b,c
        arrayList.add(1,"e");
        System.out.println("arrayList的元素为:");//c.e.b.c
        for (int i = 0; i <arrayList.size() ; i++) {
            System.out.println(arrayList.get(i));
        }
        System.out.println("");
        System.out.println("arrayList指定元素c位置的索引为"+arrayList.indexOf("c"));//0
        System.out.println("arrayList指定元素c最后位置的索引为"+arrayList.lastIndexOf("c"));//3
        System.out.println("arrayList的指定区域为"+arrayList.subList(1,2));//e

        LinkedList linkedList = new LinkedList();
        linkedList.add("a");
        linkedList.add("b");
        linkedList.add("c");
        linkedList.add("d");
        System.out.println("列表开头元素为:"+linkedList.getFirst()+"列表结尾元素为:"+linkedList.getLast());//a...d
        linkedList.addFirst("rr");
        System.out.println("列表中所有元素:"+linkedList);//rr a  b  c  d
        linkedList.removeLast();
        System.out.println("列表结尾元素为:"+linkedList.getLast());//c
    }
}
